import { Service , Inject } from "typedi";
import { getRepository,getConnection, Brackets } from "typeorm";
import {ThinkEntity} from '../entity/ThinkEntity';

@Service()
export class ClassListDao{

    public async getClassScreen(entity_Name:string): Promise<any> {

        return await     getRepository(`${entity_Name}`)
                            .createQueryBuilder(`${entity_Name}`)
                            .getMany();
    }

    public async getPaintThink(params:{PaintStyle:number,PaintTheme:number,PaintRaw:number,think_Page:number,think_Count:number}): Promise<any> {

        return await     getRepository(ThinkEntity)
        .createQueryBuilder('ThinkEntity')
        .where(`think_Paint_Style ${params.PaintStyle == 0?'<>':'='} :styleIndex`, { styleIndex: params.PaintStyle})
        .andWhere(new Brackets(qb => {
            qb.where(`think_Paint_Theme ${params.PaintTheme == 0?'<>':'='} :themeIndex`, { themeIndex: params.PaintTheme })
              .andWhere(`think_Paint_Raw ${params.PaintRaw == 0?'<>':'='} :rawIndex`, { rawIndex: params.PaintRaw })
              .andWhere("think_Category = 2")
          }))
        .leftJoinAndSelect('ThinkEntity.think_Time','TimeEntity',)
        .leftJoinAndSelect('ThinkEntity.think_Country','CountryEntity',)
        .orderBy("ThinkEntity.think_LikeType", "DESC")
        .skip(params.think_Page*params.think_Count)
        .take(params.think_Count)
        .getMany()
    }

    public async getAncientThink(params:{AncientPosition:number,AncientType:number,think_Page:number,think_Count:number}): Promise<any> {

        return await     getRepository(ThinkEntity)
        .createQueryBuilder('ThinkEntity')
        .where(`think_Ancient_Position ${params.AncientPosition == 0?'<>':'='} :styleIndex`, { styleIndex: params.AncientPosition})
        .andWhere(new Brackets(qb => {
            qb.where(`think_Ancient_Type ${params.AncientType == 0?'<>':'='} :themeIndex`, { themeIndex: params.AncientType })
              .andWhere("think_Category = 3")
          }))
        .leftJoinAndSelect('ThinkEntity.think_Time','TimeEntity',)
        .leftJoinAndSelect('ThinkEntity.think_Country','CountryEntity',)
        .orderBy("ThinkEntity.think_LikeType", "DESC")
        .skip(params.think_Page*params.think_Count)
        .take(params.think_Count)
        .getMany()
    }
    
}